namespace SimpleWebServices.Web.UI.Html
{
    using System;
    using SimpleWebServices;
    using SimpleWebServices.Web.UI.Html.Elements;
    using Xunit;

    public sealed class LabelledControlFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<LabelledControl>()
                .DerivesFrom<object>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new LabelledControl());
        }

        [Fact]
        public void ctor_IControl()
        {
            Select expected = new Select("example")
            {
                Title = "test"
            };

            LabelledControl obj = new LabelledControl(expected);
            
            Select actual = obj.Control as Select;

            Assert.Same(expected, actual);
            Assert.Equal<string>("label-example", obj.Label.Id);
            Assert.Equal<string>("test", obj.Label.Title);
            Assert.Equal<string>("test", (obj.Label.Elements[0] as TextString).Value);
        }

        [Fact]
        public void ctor_IControlNull()
        {
            Assert.Throws<ArgumentNullException>(() => new LabelledControl(null));
        }

        [Fact]
        public void ctor_IControl_string()
        {
            Select expected = new Select("example")
            {
                Title = "test"
            };

            LabelledControl obj = new LabelledControl(expected, "text");

            Select actual = obj.Control as Select;

            Assert.Same(expected, actual);
            Assert.Equal<string>("label-example", obj.Label.Id);
            Assert.Equal<string>("test", obj.Label.Title);
            Assert.Equal<string>("text", (obj.Label.Elements[0] as TextString).Value);
        }

        [Fact]
        public void ctor_IControlNull_string()
        {
            Assert.Throws<ArgumentNullException>(() => new LabelledControl(null, "text"));
        }

        [Fact]
        public void prop_Control()
        {
            Assert.True(new PropertyExpectations(typeof(LabelledControl).GetProperty("Control"))
                .TypeIs<IControl>()
                .DefaultValueIsNull()
                .Result);
        }

        [Fact]
        public void prop_Label()
        {
            Assert.True(new PropertyExpectations(typeof(LabelledControl).GetProperty("Label"))
                .IsAutoProperty<Label>()
                .Result);
        }
    }
}